<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "99%",
    },
    height: {
      type: String,
      default: "99%",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        title: {
          text: "北侧主梁主腹板1/4跨（东）",
          textStyle: {
            color: "#3b7cbd",
          },
        },
        xAxis: {
          name: "Sa(MPa)",
          type: "category",
          data: [
            2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5,
            57.5, 62.5, 67.5, 72.5,
          ],
          axisLabel: {
            textStyle: {
              color: "#3b7cbd",
            },
          },
          axisLine: {
            lineStyle: {
              color: "#3b7cbd",
            },
          },
        },
        yAxis: {
          name: "Frequency",
          type: "value",
          axisLabel: {
            textStyle: {
              color: "#3b7cbd",
            },
          },
          axisLine: {
            lineStyle: {
              color: "#3b7cbd",
            },
          },
        },
        series: [
          {
            data: [
              53.0, 61.0, 56.0, 45.0, 45.0, 21.0, 23.0, 16.0, 10.0, 4.0, 3.0,
              4.0, 2.0, 0.0, 1.0,
            ],
            type: "bar",
            itemStyle: {
              normal: {
                color: () => {
                  return "#3b7cbd";
                },
                lable: {
                  color: "#3b7cbd",
                },
              },
            },
          },
        ],
      });
    },
  },
};
</script>
